<?php
// +----------------------------------------------------------------------
// | 会员卡开卡数据登记
// +----------------------------------------------------------------------
// | Author: TongBC <501468940@qq.com>
// +----------------------------------------------------------------------
// | Date  : 2015/05/20
// +----------------------------------------------------------------------
include_once '/var/www/html/new/d/common/header.html';
include_once '/var/www/html/new/d/common/left.html';
include_once '/var/www/html/new/d/common/func.inc.php';
include_once '/var/www/html/new/d/class//MemberAccount.class.php';
include_once '/var/www/html/new/d/class/abc/Member.class.php';
use pft\Member\MemberAccount;

$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$did = $_REQUEST['did'] + 0;
if(!isset($_REQUEST['did']) || $did==0) exit('非法操作');

if($did==$_SESSION['sid']) exit('<script>alert("不能为自己办理会员卡");history.go(-1);</script>');



// 创建分销关系
// if(!abc777\Member::RelationShip($_SESSION['sid'], $did)) exit('分销关系确立失败');
$mem = new MemberAccount($GLOBALS['le'], $_SESSION['sid']);
$ret = $mem->createRelationship($_SESSION['sid'], $did, 0, 0);


$sel_account = "select account from pft_member where id=$did limit 1";
$GLOBALS['le']->query($sel_account);
$GLOBALS['le']->fetch_assoc();
if($changeIdentity && ismobile( $this->db->f('account'))){
	$new_account = $this->_generateAccount(1);
	$upd_account = "update pft_member set account='$new_account' where id=$son_id limit 1";
	$this->db->query($upd_account);
}


$sid = $_SESSION['sid'];// 供应商ID
// tpl 变量
$var = array(
	'cid'            => 0, // pft_member_card ID，==0 表示创建
	'dname'          => $_SESSION['dname'],// 开卡单位名称
	'card_no'        => '',// IC 卡显示编号
	'notice_type'    => 0,// 消费通知类型
	'physics_no'     => '',// IC 卡物理编号，不可手动输入
	'daily_buy_limit'=> -1,// 单日购买次数
	'buy_interval'   => -1,// 每次消费间隔时间
	'buy_num_limit'  => -1,// 每次消费最多购买票数
	'config_id'      => 0, // 消费限制配置ID
	'status'         => 0,
);

// 更新 pft_member mCardtime 用于排序
$sql = "update pft_member set mCardtime=now() where id=$did limit 1";
$GLOBALS['le']->query($sql);

// 会员卡信息
$sql = "select c.id as cid,c.card_no,c.physics_no,c.notice_type,c.status,m.dname from pft_member_card c left join pft_member m on c.apply_did=m.id where c.memberID=$did and c.status<4 order by c.id desc limit 1";
$GLOBALS['le']->query($sql);
$data1 = $GLOBALS['le']->fetch_assoc();
if(is_array($data1)) $var = array_merge($var, $data1);
if($data1['status']==2) exit('会员卡禁用');
if($data1['status']==3) exit('会员卡冻结');

// 购买消费限制配置
$sql = "select id as config_id,daily_buy_limit,buy_interval,buy_num_limit from pft_card_consume_conf where apply_did=$sid and memberID=$did limit 1";
$GLOBALS['le']->query($sql);
$data2 = $GLOBALS['le']->fetch_assoc();
if(is_array($data2)) $var = array_merge($var, $data2);


include('/var/www/html/new/d/tpl/membercard/mem_msg.html');
include('/var/www/html/new/d/common/footer.html');
?>